/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ies.domain.model.web.converter;

import com.ies.domain.model.Permissao;
import com.ies.domain.model.repository.facades.PermissaoFacade;
import com.ies.domain.model.util.JpaPool;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author gustavo
 */
@FacesConverter(value="PermissaoConverter")
public class PermissaoConverter implements Converter{
    
    /**
     *
     * @param context
     * @param component
     * @param value
     * @return
     */
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        try {
            PermissaoFacade esf = (PermissaoFacade) JpaPool.get(Permissao.class);

            Permissao est = (Permissao) esf.find(Long.parseLong(value.replaceAll("\\D", "")));

            return est;
        } catch (Exception ex) {
            return null;
        }

    }

    /**
     *
     * @param context
     * @param component
     * @param value
     * @return
     */
    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        return String.valueOf(value);
    }

   
    
}
